package com.beiding.dao.impl;

import com.beiding.timeout.dao.TimeShaftDescription;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Repository;

@Repository
public class TimeShaftDescriptionImpl implements TimeShaftDescription {

    private HashOperations<String, Object, Object> operations;

    public TimeShaftDescriptionImpl(RedisTemplate redisTemplate, StringRedisSerializer stringRedisSerializer) {
        redisTemplate.setKeySerializer(stringRedisSerializer);

        operations = redisTemplate.opsForHash();
    }

    @Override
    public Long getLastHeartbeat() {
        return (Long) operations.get("test:description", "lastHeartbeat");
    }

    @Override
    public void updateLastHeartbeat(long lastHeartbeat) {
        operations.put("test:description", "lastHeartbeat", lastHeartbeat);
    }

    @Override
    public Integer getStep() {
        return (Integer) operations.get("test:description", "step");
    }

    @Override
    public void setStep(int step) {
        operations.put("test:description", "step", step);
    }

    @Override
    public Integer getHeartbeatInterval() {
        return (Integer) operations.get("test:description", "heartbeatInterval");
    }


    @Override
    public void setHeartbeatInterval(int heartbeatInterval) {
        operations.put("test:description", "heartbeatInterval", heartbeatInterval);
    }

    @Override
    public String getHolder() {
        return (String) operations.get("test:description", "holder");
    }

    @Override
    public void setHolder(String id) {
        operations.put("test:description", "holder", id);
    }
}
